
package xdev.junit;


import junit.framework.Assert;

import org.junit.Ignore;


/**
 * A set of assertion methods useful for writing tests. Only failed assertions
 * are recorded. These methods can be used directly:
 * <code>Assert2.assertEquals(...)</code>, however, they read better if they are
 * referenced through static import:<br/>
 * 
 * <pre>
 * import static xdev.junit.Assert2.*;
 *    ...
 *    assertEquals(...);
 * </pre>
 * 
 * @see AssertionError
 * @see Assert
 * 
 * @author RF
 * 
 */
@Ignore
public class Assert2
{	
	/**
	 * Removes breaks "\n" and spaces.
	 * 
	 * @param str
	 *            to normalize
	 * @return the normalized String
	 */
	protected static String ignoreSpacesAndBreaks(String str)
	{
		
		return str.replaceAll("\n","").replaceAll(" ","").trim();
	}
	

	/**
	 * Asserts that two {@link String}s are equal (spaces and breaks not
	 * considered). If they are not, an {@link AssertionError} is thrown with
	 * the given message. If <code>expected</code> and <code>actual</code> are
	 * <code>null</code>, they are considered equal.
	 * 
	 * @param message
	 *            the identifying message for the {@link AssertionError} (
	 *            <code>null</code> okay)
	 * @param expected
	 *            expected value
	 * @param actual
	 *            actual value
	 */
	public static void assertEqualsWithOutSpaceAndBreaks(String message, String expected,
			String actual)
	{
		Assert.assertEquals(message,ignoreSpacesAndBreaks(expected),ignoreSpacesAndBreaks(actual));
	}
	

	/**
	 * Asserts that two {@link String}s are equal (spaces and breaks not
	 * considered). If they are not, an {@link AssertionError} is thrown with
	 * the given message. If <code>expected</code> and <code>actual</code> are
	 * <code>null</code>, they are considered equal.
	 * 
	 * @param expected
	 *            expected value
	 * @param actual
	 *            actual value
	 */
	public static void assertEqualsWithOutSpaceAndBreaks(String expected, String actual)
	{
		Assert2.assertEqualsWithOutSpaceAndBreaks(null,expected,actual);
	}
}
